
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>基础 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="collections.html" />
    
    
    <link rel="prev" href="../../" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="basics.html">
            
                <a href="basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="collections.html">
            
                <a href="collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="enum.html">
            
                <a href="enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="pattern-matching.html">
            
                <a href="pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="control-structures.html">
            
                <a href="control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="functions.html">
            
                <a href="functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="pipe-operator.html">
            
                <a href="pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="mix.html">
            
                <a href="mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="sigils.html">
            
                <a href="sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="documentation.html">
            
                <a href="documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="testing.html">
            
                <a href="testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="comprehensions.html">
            
                <a href="comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="strings.html">
            
                <a href="strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="date-time.html">
            
                <a href="date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="mix-tasks.html">
            
                <a href="mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="iex-helpers.html">
            
                <a href="iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../advanced/erlang.html">
            
                <a href="../advanced/erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../advanced/error-handling.html">
            
                <a href="../advanced/error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../advanced/escripts.html">
            
                <a href="../advanced/escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../advanced/concurrency.html">
            
                <a href="../advanced/concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../advanced/otp-concurrency.html">
            
                <a href="../advanced/otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../advanced/otp-supervisors.html">
            
                <a href="../advanced/otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../advanced/otp-distribution.html">
            
                <a href="../advanced/otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../advanced/metaprogramming.html">
            
                <a href="../advanced/metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="../advanced/umbrella-projects.html">
            
                <a href="../advanced/umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../advanced/typespec.html">
            
                <a href="../advanced/typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="../advanced/behaviours.html">
            
                <a href="../advanced/behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="../advanced/gen-stage.html">
            
                <a href="../advanced/gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="../advanced/protocols.html">
            
                <a href="../advanced/protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="../advanced/nerves.html">
            
                <a href="../advanced/nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../specifics/plug.html">
            
                <a href="../specifics/plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../specifics/eex.html">
            
                <a href="../specifics/eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../specifics/ets.html">
            
                <a href="../specifics/ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../specifics/mnesia.html">
            
                <a href="../specifics/mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../specifics/debugging.html">
            
                <a href="../specifics/debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../libraries/guardian.html">
            
                <a href="../libraries/guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../libraries/poolboy.html">
            
                <a href="../libraries/poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../libraries/benchee.html">
            
                <a href="../libraries/benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../libraries/bypass.html">
            
                <a href="../libraries/bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../libraries/distillery.html">
            
                <a href="../libraries/distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../libraries/stream-data.html">
            
                <a href="../libraries/stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >基础</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x5B89;&#x88C5;&#xFF0C;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x548C;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&#x3002;</p>
<h2 id="&#x5B89;&#x88C5;">&#x5B89;&#x88C5;</h2>
<h3 id="&#x5B89;&#x88C5;-elixir">&#x5B89;&#x88C5; Elixir</h3>
<p>&#x6BCF;&#x4E2A;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x5B89;&#x88C5;&#x8BF4;&#x660E;&#x53EF;&#x4EE5;&#x5728; elixir-lang.org &#x7F51;&#x7AD9;&#x4E0A; <a href="http://elixir-lang.org/install.html" target="_blank">Installing Elixir</a> &#x90E8;&#x5206;&#x627E;&#x5230;&#x3002;</p>
<p>&#x5B89;&#x88C5;&#x540E;&#x4F60;&#x53EF;&#x4EE5;&#x5F88;&#x8F7B;&#x677E;&#x5730;&#x786E;&#x8BA4;&#x6240;&#x5B89;&#x88C5;&#x7684;&#x7248;&#x672C;&#x3002;</p>
<pre><code>% elixir -v
Erlang/OTP {{ site.erlang.OTP }} [erts-{{ site.erlang.erts }}] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir {{ site.elixir.version }}
</code></pre><h3 id="&#x4EA4;&#x4E92;&#x6A21;&#x5F0F;">&#x4EA4;&#x4E92;&#x6A21;&#x5F0F;</h3>
<p>Elixir &#x81EA;&#x5E26;&#x4E86;<code>iex</code>&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x4EA4;&#x4E92; shell&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x968F;&#x65F6;&#x8BA1;&#x7B97; Elixir &#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x503C;&#x3002;</p>
<p>&#x8FD0;&#x884C;<code>iex</code>&#x547D;&#x4EE4;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x6559;&#x7A0B;&#xFF1A;</p>
<pre><code>Erlang/OTP {{ site.erlang.OTP }} [erts-{{ site.erlang.erts }}] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir ({{ site.elixir.version }}) - press Ctrl+C to exit (type h() ENTER for help)
iex&gt;
</code></pre><p>&#x8BA9;&#x6211;&#x4EEC;&#x7EE7;&#x7EED;&#x8F93;&#x5165;&#x51E0;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x8BD5;&#x8BD5;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-number">2</span>+<span class="hljs-number">3</span>
<span class="hljs-number">5</span>
iex&gt; <span class="hljs-number">2</span>+<span class="hljs-number">3</span> == <span class="hljs-number">5</span>
<span class="hljs-keyword">true</span>
iex&gt; String.length(<span class="hljs-string">&quot;The quick brown fox jumps over the lazy dog&quot;</span>)
<span class="hljs-number">43</span>
</code></pre>
<p>&#x5982;&#x679C;&#x4F60;&#x73B0;&#x5728;&#x8FD8;&#x65E0;&#x6CD5;&#x7406;&#x89E3;&#x6240;&#x6709;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x8BF7;&#x4E0D;&#x8981;&#x62C5;&#x5FC3;&#xFF0C;&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x4F60;&#x80FD;&#x6709;&#x6240;&#x4F53;&#x4F1A;&#x3002;</p>
<h2 id="&#x57FA;&#x672C;&#x7C7B;&#x578B;">&#x57FA;&#x672C;&#x7C7B;&#x578B;</h2>
<h3 id="&#x6574;&#x6570;&#x7C7B;&#x578B;">&#x6574;&#x6570;&#x7C7B;&#x578B;</h3>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-number">255</span>
<span class="hljs-number">255</span>
</code></pre>
<p>Elixir &#x8BED;&#x8A00;&#x672C;&#x8EAB;&#x5C31;&#x652F;&#x6301;&#x4E8C;&#x8FDB;&#x5236;&#x3001;&#x516B;&#x8FDB;&#x5236;&#x548C;&#x5341;&#x516D;&#x8FDB;&#x5236;&#x7684;&#x6574;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; 0b011<span class="hljs-number">0</span>
<span class="hljs-number">6</span>
iex&gt; 0o644
<span class="hljs-number">420</span>
iex&gt; <span class="hljs-number">0x1F</span>
<span class="hljs-number">31</span>
</code></pre>
<h3 id="&#x6D6E;&#x70B9;&#x7C7B;&#x578B;">&#x6D6E;&#x70B9;&#x7C7B;&#x578B;</h3>
<p>&#x5728; Elixir &#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x6D6E;&#x70B9;&#x6570;&#x8981;&#x6C42;&#x5C0F;&#x6570;&#x70B9;&#x4E4B;&#x524D;&#x5FC5;&#x987B;&#x6709;&#x81F3;&#x5C11;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#xFF1B;&#x652F;&#x6301; 64 &#x4F4D;&#x591A;&#x7CBE;&#x5EA6;&#x548C; <code>e</code> &#x8868;&#x793A;&#x7684;&#x79D1;&#x5B66;&#x8BA1;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-number">3.14</span>
 <span class="hljs-number">3.14</span>
iex&gt; .<span class="hljs-number">14</span>
** (SyntaxError) <span class="hljs-symbol">iex:</span><span class="hljs-number">2</span><span class="hljs-symbol">:</span> syntax error <span class="hljs-symbol">before:</span> <span class="hljs-string">&apos;.&apos;</span>
iex&gt; <span class="hljs-number">1.0</span>e-<span class="hljs-number">10</span>
<span class="hljs-number">1.0</span>e-<span class="hljs-number">10</span>
</code></pre>
<h3 id="&#x5E03;&#x5C14;&#x7C7B;&#x578B;">&#x5E03;&#x5C14;&#x7C7B;&#x578B;</h3>
<p>Elixir &#x652F;&#x6301; <code>true</code> &#x548C; <code>false</code> &#x4E24;&#x79CD;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x9664;&#x4E86; <code>false</code> &#x548C; <code>nil</code> &#x4E4B;&#x5916;&#x6240;&#x6709;&#x7684;&#x503C;&#x90FD;&#x4E3A;&#x771F;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">true</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-keyword">false</span>
<span class="hljs-keyword">false</span>
</code></pre>
<h3 id="&#x539F;&#x5B50;&#x7C7B;&#x578B;">&#x539F;&#x5B50;&#x7C7B;&#x578B;</h3>
<p>&#x539F;&#x5B50;&#x7C7B;&#x578B;&#x662F;&#x540D;&#x5B57;&#x548C;&#x4EE3;&#x8868;&#x7684;&#x503C;&#x76F8;&#x540C;&#x7684;&#x5E38;&#x91CF;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x719F;&#x6089; Ruby&#xFF0C;&#x5B83;&#x4EEC;&#x548C;Ruby&#x4E2D;&#x7684;&#x7B26;&#x53F7;&#x662F;&#x540C;&#x4E49;&#x7684;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-symbol">:foo</span>
<span class="hljs-symbol">:foo</span>
iex&gt; <span class="hljs-symbol">:foo</span> == <span class="hljs-symbol">:bar</span>
<span class="hljs-keyword">false</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5E03;&#x5C14;&#x503C; <code>true</code> &#x548C; <code>false</code> &#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F;&#x5BF9;&#x5E94;&#x7684;&#x539F;&#x5B50; <code>:true</code> &#x548C; <code>:false</code></p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">true</span> |&gt; is_atom
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-symbol">:true</span> |&gt; is_boolean
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-symbol">:true</span> === <span class="hljs-keyword">true</span>
<span class="hljs-keyword">true</span>
</code></pre>
<p>Elixir &#x6A21;&#x5757;&#x7684;&#x540D;&#x5B57;&#x4E5F;&#x662F;&#x539F;&#x5B50;&#xFF0C;&#x5373;&#x4F7F;&#x5B9E;&#x9645;&#x4E0A;&#x8FD8;&#x4E0D;&#x5B58;&#x5728;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;<code>MyApp.MyModule</code> &#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x5408;&#x6CD5;&#x7684;&#x539F;&#x5B50;&#x540D;&#x79F0;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; is_atom(MyApp.MyModule)
<span class="hljs-keyword">true</span>
</code></pre>
<p>Elixir &#x4EE5;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x5F00;&#x59CB;&#x7684;&#x522B;&#x540D;&#x4E5F;&#x662F;&#x539F;&#x5B50;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; is_atom(JustMyAliasTest)
<span class="hljs-keyword">true</span>
</code></pre>
<p>&#x539F;&#x5B50;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x76F4;&#x63A5;&#x5F15;&#x7528; Erlang &#x6807;&#x51C6;&#x5E93;&#x7684;&#x6A21;&#x5757;&#xFF0C;&#x5305;&#x62EC;&#x5185;&#x7F6E;&#x7684;&#x6A21;&#x5757;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-symbol">:crypto</span>.strong_rand_bytes <span class="hljs-number">3</span>
&lt;&lt;<span class="hljs-number">23</span>, <span class="hljs-number">104</span>, <span class="hljs-number">108</span>&gt;&gt;
</code></pre>
<h3 id="&#x5B57;&#x7B26;&#x4E32;">&#x5B57;&#x7B26;&#x4E32;</h3>
<p>Elixir &#x7684;&#x5B57;&#x7B26;&#x4E32;&#x662F; UTF-8 &#x7F16;&#x7801;&#x7684;&#xFF0C;&#x7528;&#x53CC;&#x5F15;&#x53F7;&#x5305;&#x4F4F;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-string">&quot;Hello&quot;</span>
<span class="hljs-string">&quot;Hello&quot;</span>
iex&gt; <span class="hljs-string">&quot;dzi&#x119;kuj&#x119;&quot;</span>
<span class="hljs-string">&quot;dzi&#x119;kuj&#x119;&quot;</span>
</code></pre>
<p>&#x5B57;&#x7B26;&#x4E32;&#x652F;&#x6301;&#x6362;&#x884C;&#x7B26;&#x548C;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-string">&quot;foo
...&gt; bar&quot;</span>
<span class="hljs-string">&quot;foo\nbar&quot;</span>
iex&gt; <span class="hljs-string">&quot;foo\nbar&quot;</span>
<span class="hljs-string">&quot;foo\nbar&quot;</span>
</code></pre>
<p>Elixir &#x8FD8;&#x5305;&#x542B;&#x5F88;&#x591A;&#x590D;&#x6742;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;&#x5F53;&#x6211;&#x4EEC;&#x5B66;&#x5230;<a href="../collections">&#x96C6;&#x5408;</a>&#x548C;<a href="../functions">&#x51FD;&#x6570;</a>&#x7684;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x4F1A;&#x5B66;&#x5230;&#x66F4;&#x591A;&#x5173;&#x4E8E;&#x8FD9;&#x65B9;&#x9762;&#x7684;&#x77E5;&#x8BC6;&#x3002;</p>
<h2 id="&#x57FA;&#x672C;&#x64CD;&#x4F5C;">&#x57FA;&#x672C;&#x64CD;&#x4F5C;</h2>
<h3 id="&#x7B97;&#x672F;&#x8FD0;&#x7B97;">&#x7B97;&#x672F;&#x8FD0;&#x7B97;</h3>
<p>&#x5982;&#x4F60;&#x6240;&#x60F3;&#xFF0C;Elixir &#x652F;&#x6301;&#x57FA;&#x672C;&#x7684; <code>+</code>&#x3001;<code>-</code>&#x3001;<code>*</code>&#x3001;<code>/</code>&#x64CD;&#x4F5C;&#x7B26;&#xFF0C;&#x4E0D;&#x8FC7;&#x8981;&#x6CE8;&#x610F; <code>/</code> &#x7684;&#x7ED3;&#x679C;&#x662F;&#x6D6E;&#x70B9;&#x6570;&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-number">2</span> + <span class="hljs-number">2</span>
<span class="hljs-number">4</span>
iex&gt; <span class="hljs-number">2</span> - <span class="hljs-number">1</span>
<span class="hljs-number">1</span>
iex&gt; <span class="hljs-number">2</span> * <span class="hljs-number">5</span>
<span class="hljs-number">10</span>
iex&gt; <span class="hljs-number">10</span> / <span class="hljs-number">5</span>
<span class="hljs-number">2.0</span>
</code></pre>
<p>&#x5982;&#x679C;&#x4F60;&#x9700;&#x8981;&#x6574;&#x6570;&#x9664;&#x6CD5;&#x548C;&#x6C42;&#x4F59;&#xFF0C;Elixir &#x63D0;&#x4F9B;&#x4E86;&#x4E24;&#x4E2A;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; div(<span class="hljs-number">10</span>, <span class="hljs-number">5</span>)
<span class="hljs-number">2</span>
iex&gt; rem(<span class="hljs-number">10</span>, <span class="hljs-number">3</span>)
<span class="hljs-number">1</span>
</code></pre>
<h3 id="&#x5E03;&#x5C14;&#x8FD0;&#x7B97;">&#x5E03;&#x5C14;&#x8FD0;&#x7B97;</h3>
<p>Elixir &#x63D0;&#x4F9B;&#x4E86; <code>||</code>&#x3001;<code>&amp;&amp;</code> &#x548C; <code>!</code> &#x5E03;&#x5C14;&#x64CD;&#x4F5C;&#x7B26;&#xFF0C;&#x5B83;&#x4EEC;&#x652F;&#x6301;&#x4EFB;&#x4F55;&#x7C7B;&#x578B;&#x7684;&#x64CD;&#x4F5C;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; -<span class="hljs-number">20</span> || <span class="hljs-keyword">true</span>
-<span class="hljs-number">20</span>
iex&gt; <span class="hljs-keyword">false</span> || <span class="hljs-number">42</span>
<span class="hljs-number">42</span>

iex&gt; <span class="hljs-number">42</span> &amp;&amp; <span class="hljs-keyword">true</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-number">42</span> &amp;&amp; <span class="hljs-keyword">nil</span>
<span class="hljs-keyword">nil</span>

iex&gt; !<span class="hljs-number">42</span>
<span class="hljs-keyword">false</span>
iex&gt; !<span class="hljs-keyword">false</span>
<span class="hljs-keyword">true</span>
</code></pre>
<p>&#x8FD8;&#x6709;&#x4E09;&#x4E2A;&#x64CD;&#x4F5C;&#x7B26;&#xFF08;<code>and</code>&#x3001;<code>or</code>&#x3001;<code>not</code>&#xFF09;&#xFF0C;&#x5B83;&#x4EEC;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;<em>&#x5FC5;&#x987B;</em>&#x662F;&#x5E03;&#x5C14;&#x7C7B;&#x578B;&#xFF08;<code>true</code> &#x548C; <code>false</code>&#xFF09;:</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">true</span> <span class="hljs-keyword">and</span> <span class="hljs-number">42</span>
<span class="hljs-number">42</span>
iex&gt; <span class="hljs-keyword">false</span> <span class="hljs-keyword">or</span> <span class="hljs-keyword">true</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-keyword">not</span> <span class="hljs-keyword">false</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-number">42</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">true</span>
** (ArgumentError) argument <span class="hljs-symbol">error:</span> <span class="hljs-number">42</span>
iex&gt; <span class="hljs-keyword">not</span> <span class="hljs-number">42</span>
** (ArgumentError) argument error
</code></pre>
<p>&#x5907;&#x6CE8;&#xFF1A;Elixir &#x662F;&#x57FA;&#x4E8E; Erlang VM (BEAM) &#x4E0A;&#x7684;&#x8BED;&#x8A00;&#x3002;&#x5982;&#x679C;&#x4F60;&#x662F; Erlang &#x5F00;&#x53D1;&#x4EBA;&#x5458;&#xFF0C;&#x5176;&#x5B9E; <code>and</code>&#xFF0C;<code>or</code> &#x662F;&#x76F8;&#x5E94;&#x7684; <code>andalso</code> &#x548C; <code>orelse</code> &#x64CD;&#x4F5C;&#x7B26;&#x3002;&#x6240;&#x4EE5;&#x5B83;&#x4EEC;&#x4E0D;&#x4F1A;&#x8BA1;&#x7B97;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x503C;&#xFF0C;&#x800C;&#x53EA;&#x4F1A;&#x8BA1;&#x7B97;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<h3 id="&#x6BD4;&#x8F83;">&#x6BD4;&#x8F83;</h3>
<p>Elixir &#x6709;&#x6211;&#x4EEC;&#x4E60;&#x60EF;&#x7684;&#x4E00;&#x5207;&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26; &#xFF1A;<code>==</code>, <code>!=</code>, <code>===</code>, <code>!==</code>, <code>&lt;=</code>, <code>&gt;=</code>, <code>&lt;</code> &#x548C; <code>&gt;</code>&#x3002;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-number">1</span> &gt; <span class="hljs-number">2</span>
<span class="hljs-keyword">false</span>
iex&gt; <span class="hljs-number">1</span> != <span class="hljs-number">2</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-number">2</span> == <span class="hljs-number">2</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-number">2</span> &lt;= <span class="hljs-number">3</span>
<span class="hljs-keyword">true</span>
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x6574;&#x6570;&#x548C;&#x6D6E;&#x70B9;&#x6570;&#x7684;&#x4E25;&#x683C;&#x6BD4;&#x8F83;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>===</code> &#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-number">2</span> == <span class="hljs-number">2.0</span>
<span class="hljs-keyword">true</span>
iex&gt; <span class="hljs-number">2</span> === <span class="hljs-number">2.0</span>
<span class="hljs-keyword">false</span>
</code></pre>
<p>Elixir &#x6709;&#x4E00;&#x4E2A;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x7279;&#x6027;&#xFF0C;&#x90A3;&#x5C31;&#x662F;&#x4EFB;&#x610F;&#x4E24;&#x4E2A;&#x7C7B;&#x578B;&#x4E4B;&#x95F4;&#x90FD;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#xFF0C;&#x8FD9;&#x5728;&#x6392;&#x5E8F;&#x7684;&#x65F6;&#x5019;&#x975E;&#x5E38;&#x6709;&#x7528;&#x3002;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x53BB;&#x8BB0;&#x4F4F;&#x6BD4;&#x8F83;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#xFF0C;&#x4F46;&#x662F;&#x77E5;&#x9053;&#x4E86;&#x4E5F;&#x6CA1;&#x574F;&#x5904; &#xFF1A;</p>
<pre><code class="lang-elixir">number &lt; atom &lt; reference &lt; function &lt; port &lt; pid &lt; tuple &lt; map &lt; list &lt; bitstring
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x7279;&#x6027;&#x53EF;&#x4EE5;&#x5BFC;&#x81F4;&#x4E00;&#x4E9B;&#x975E;&#x5E38;&#x6709;&#x8DA3;&#x4F46;&#x662F;&#x5B8C;&#x5168;&#x5408;&#x6CD5;&#xFF0C;&#x800C;&#x4E14;&#x5728;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x4E2D;&#x5F88;&#x96BE;&#x770B;&#x5230;&#x7684;&#x6BD4;&#x8F83; &#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-symbol">:hello</span> &gt; <span class="hljs-number">999</span>
<span class="hljs-keyword">true</span>
iex&gt; {<span class="hljs-symbol">:hello</span>, <span class="hljs-symbol">:world</span>} &gt; [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
<span class="hljs-keyword">false</span>
</code></pre>
<h3 id="&#x5B57;&#x7B26;&#x4E32;&#x63D2;&#x503C;">&#x5B57;&#x7B26;&#x4E32;&#x63D2;&#x503C;</h3>
<p>&#x5982;&#x679C;&#x4F60;&#x4F7F;&#x7528;&#x8FC7; Ruby&#xFF0C;&#x90A3;&#x4E48; Elixir &#x7684;&#x5B57;&#x7B26;&#x4E32;&#x63D2;&#x503C;&#x770B;&#x8D77;&#x6765;&#x4F1A;&#x5F88;&#x719F;&#x6089;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; name = <span class="hljs-string">&quot;Sean&quot;</span>
iex&gt; <span class="hljs-string">&quot;Hello <span class="hljs-subst">#{name}</span>&quot;</span>
<span class="hljs-string">&quot;Hello Sean&quot;</span>
</code></pre>
<h3 id="&#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;">&#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;</h3>
<p>&#x4F7F;&#x7528; <code>&lt;&gt;</code> &#x64CD;&#x4F5C;&#x7B26;&#x8FDB;&#x884C;&#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; name = <span class="hljs-string">&quot;Sean&quot;</span>
iex&gt; <span class="hljs-string">&quot;Hello &quot;</span> &lt;&gt; name
<span class="hljs-string">&quot;Hello Sean&quot;</span>
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../../" class="navigation navigation-prev " aria-label="Previous page: Introduction">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="collections.html" class="navigation navigation-next " aria-label="Next page: 集合">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.2.1","title":"基础","level":"1.2","depth":1,"next":{"title":"集合","level":"1.3","depth":1,"path":"lessons/basics/collections.md","ref":"lessons/basics/collections.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/basics/basics.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

